﻿using Microsoft.AspNetCore.Http;

namespace Luka;

/// <summary>
/// 自定义异常消息
/// </summary>
[NotScanned, AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public sealed class ErrorMessageAttribute : Attribute
{
    /// <summary>
    /// 自定义消息
    /// </summary>
    public string? Message { get; set; }

    /// <summary>
    /// 错误代码(默认400)
    /// </summary>
    public int Code { get; set; } = StatusCodes.Status400BadRequest;

    /// <summary>
    /// 构造函数
    /// </summary>
    public ErrorMessageAttribute()
    {
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    public ErrorMessageAttribute(string message, int code = StatusCodes.Status400BadRequest)
    {
        Message = message;
        Code = code;
    }
}